package com.gitub.ybqdren.recursion;

/**
 * @author Wen(Joan) Zhao
 * @version v1.0
 * @description
 **/
public class Sum {
    public static int sum(int[] arr){
        return sum(arr,0);
    }

    private static int sum(int[] arr,int l){
        if(l == arr.length){
            return 0;
        }

        return arr[l] + sum(arr,l+1);  // [l+1...arr.length]
    }

    public static void main(String[] args) {
        int nums[] = {1,2,3,4,5,6,7,8};
        System.out.println(sum(nums));
    }

}
